<?php


abstract class BaseReservations extends BaseObject  implements Persistent {


  const PEER = 'ReservationsPeer';

	
	protected static $peer;

	
	protected $id;

	
	protected $created;

	
	protected $datenew;

	
	protected $title;

	
	protected $chairs;

	
	protected $isdone;

	
	protected $description;

	
	protected $singleReservationCustomers;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function __construct()
	{
		parent::__construct();
		$this->applyDefaultValues();
	}

	
	public function applyDefaultValues()
	{
		$this->datenew = '2001-01-01 00:00:00';
	}

	
	public function getId()
	{
		return $this->id;
	}

	
	public function getCreated($format = 'Y-m-d H:i:s')
	{
		if ($this->created === null) {
			return null;
		}


		if ($this->created === '0000-00-00 00:00:00') {
									return null;
		} else {
			try {
				$dt = new DateTime($this->created);
			} catch (Exception $x) {
				throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created, true), $x);
			}
		}

		if ($format === null) {
						return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	
	public function getDatenew($format = 'Y-m-d H:i:s')
	{
		if ($this->datenew === null) {
			return null;
		}


		if ($this->datenew === '0000-00-00 00:00:00') {
									return null;
		} else {
			try {
				$dt = new DateTime($this->datenew);
			} catch (Exception $x) {
				throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->datenew, true), $x);
			}
		}

		if ($format === null) {
						return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	
	public function getTitle()
	{
		return $this->title;
	}

	
	public function getChairs()
	{
		return $this->chairs;
	}

	
	public function getIsdone()
	{
		return $this->isdone;
	}

	
	public function getDescription()
	{
		return $this->description;
	}

	
	public function setId($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = ReservationsPeer::ID;
		}

		return $this;
	} 
	
	public function setCreated($v)
	{
						if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
									try {
				if (is_numeric($v)) { 					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
															$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->created !== null || $dt !== null ) {
			
			$currNorm = ($this->created !== null && $tmpDt = new DateTime($this->created)) ? $tmpDt->format('Y-m-d H:i:s') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d H:i:s') : null;

			if ( ($currNorm !== $newNorm) 					)
			{
				$this->created = ($dt ? $dt->format('Y-m-d H:i:s') : null);
				$this->modifiedColumns[] = ReservationsPeer::CREATED;
			}
		} 
		return $this;
	} 
	
	public function setDatenew($v)
	{
						if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
									try {
				if (is_numeric($v)) { 					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
															$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->datenew !== null || $dt !== null ) {
			
			$currNorm = ($this->datenew !== null && $tmpDt = new DateTime($this->datenew)) ? $tmpDt->format('Y-m-d H:i:s') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d H:i:s') : null;

			if ( ($currNorm !== $newNorm) 					|| ($dt->format('Y-m-d H:i:s') === '2001-01-01 00:00:00') 					)
			{
				$this->datenew = ($dt ? $dt->format('Y-m-d H:i:s') : null);
				$this->modifiedColumns[] = ReservationsPeer::DATENEW;
			}
		} 
		return $this;
	} 
	
	public function setTitle($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->title !== $v) {
			$this->title = $v;
			$this->modifiedColumns[] = ReservationsPeer::TITLE;
		}

		return $this;
	} 
	
	public function setChairs($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->chairs !== $v) {
			$this->chairs = $v;
			$this->modifiedColumns[] = ReservationsPeer::CHAIRS;
		}

		return $this;
	} 
	
	public function setIsdone($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->isdone !== $v) {
			$this->isdone = $v;
			$this->modifiedColumns[] = ReservationsPeer::ISDONE;
		}

		return $this;
	} 
	
	public function setDescription($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->description !== $v) {
			$this->description = $v;
			$this->modifiedColumns[] = ReservationsPeer::DESCRIPTION;
		}

		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array(ReservationsPeer::DATENEW))) {
				return false;
			}

			if ($this->datenew !== '2001-01-01 00:00:00') {
				return false;
			}

				return true;
	} 
	
	public function hydrate($row, $startcol = 0, $rehydrate = false)
	{
		try {

			$this->id = ($row[$startcol + 0] !== null) ? (string) $row[$startcol + 0] : null;
			$this->created = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
			$this->datenew = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
			$this->title = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
			$this->chairs = ($row[$startcol + 4] !== null) ? (int) $row[$startcol + 4] : null;
			$this->isdone = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
			$this->description = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
			$this->resetModified();

			$this->setNew(false);

			if ($rehydrate) {
				$this->ensureConsistency();
			}

						return $startcol + 7; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Reservations object", $e);
		}
	}

	
	public function ensureConsistency()
	{

	} 
	
	public function reload($deep = false, PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("Cannot reload a deleted object.");
		}

		if ($this->isNew()) {
			throw new PropelException("Cannot reload an unsaved object.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ReservationsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = ReservationsPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
		$row = $stmt->fetch(PDO::FETCH_NUM);
		$stmt->closeCursor();
		if (!$row) {
			throw new PropelException('Cannot find matching row in the database to reload object values.');
		}
		$this->hydrate($row, 0, true); 
		if ($deep) {  
			$this->singleReservationCustomers = null;

		} 	}

	
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ReservationsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			ReservationsPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	public function save(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ReservationsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			ReservationsPeer::addInstanceToPool($this);
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	protected function doSave(PropelPDO $con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = ReservationsPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += ReservationsPeer::doUpdate($this, $con);
				}

				$this->resetModified(); 			}

			if ($this->singleReservationCustomers !== null) {
				if (!$this->singleReservationCustomers->isDeleted()) {
						$affectedRows += $this->singleReservationCustomers->save($con);
				}
			}

			$this->alreadyInSave = false;

		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = ReservationsPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->singleReservationCustomers !== null) {
					if (!$this->singleReservationCustomers->validate($columns)) {
						$failureMap = array_merge($failureMap, $this->singleReservationCustomers->getValidationFailures());
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ReservationsPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		$field = $this->getByPosition($pos);
		return $field;
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getCreated();
				break;
			case 2:
				return $this->getDatenew();
				break;
			case 3:
				return $this->getTitle();
				break;
			case 4:
				return $this->getChairs();
				break;
			case 5:
				return $this->getIsdone();
				break;
			case 6:
				return $this->getDescription();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = ReservationsPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getCreated(),
			$keys[2] => $this->getDatenew(),
			$keys[3] => $this->getTitle(),
			$keys[4] => $this->getChairs(),
			$keys[5] => $this->getIsdone(),
			$keys[6] => $this->getDescription(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ReservationsPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setCreated($value);
				break;
			case 2:
				$this->setDatenew($value);
				break;
			case 3:
				$this->setTitle($value);
				break;
			case 4:
				$this->setChairs($value);
				break;
			case 5:
				$this->setIsdone($value);
				break;
			case 6:
				$this->setDescription($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ReservationsPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setCreated($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setDatenew($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setTitle($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setChairs($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setIsdone($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setDescription($arr[$keys[6]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(ReservationsPeer::DATABASE_NAME);

		if ($this->isColumnModified(ReservationsPeer::ID)) $criteria->add(ReservationsPeer::ID, $this->id);
		if ($this->isColumnModified(ReservationsPeer::CREATED)) $criteria->add(ReservationsPeer::CREATED, $this->created);
		if ($this->isColumnModified(ReservationsPeer::DATENEW)) $criteria->add(ReservationsPeer::DATENEW, $this->datenew);
		if ($this->isColumnModified(ReservationsPeer::TITLE)) $criteria->add(ReservationsPeer::TITLE, $this->title);
		if ($this->isColumnModified(ReservationsPeer::CHAIRS)) $criteria->add(ReservationsPeer::CHAIRS, $this->chairs);
		if ($this->isColumnModified(ReservationsPeer::ISDONE)) $criteria->add(ReservationsPeer::ISDONE, $this->isdone);
		if ($this->isColumnModified(ReservationsPeer::DESCRIPTION)) $criteria->add(ReservationsPeer::DESCRIPTION, $this->description);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(ReservationsPeer::DATABASE_NAME);

		$criteria->add(ReservationsPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setId($this->id);

		$copyObj->setCreated($this->created);

		$copyObj->setDatenew($this->datenew);

		$copyObj->setTitle($this->title);

		$copyObj->setChairs($this->chairs);

		$copyObj->setIsdone($this->isdone);

		$copyObj->setDescription($this->description);


		if ($deepCopy) {
									$copyObj->setNew(false);

			$relObj = $this->getReservationCustomers();
			if ($relObj) {
				$copyObj->setReservationCustomers($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new ReservationsPeer();
		}
		return self::$peer;
	}

	
	public function getReservationCustomers(PropelPDO $con = null)
	{

		if ($this->singleReservationCustomers === null && !$this->isNew()) {
			$this->singleReservationCustomers = ReservationCustomersPeer::retrieveByPK($this->id, $con);
		}

		return $this->singleReservationCustomers;
	}

	
	public function setReservationCustomers(ReservationCustomers $v)
	{
		$this->singleReservationCustomers = $v;

				if ($v->getReservations() === null) {
			$v->setReservations($this);
		}

		return $this;
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
			if ($this->singleReservationCustomers) {
				$this->singleReservationCustomers->clearAllReferences($deep);
			}
		} 
		$this->singleReservationCustomers = null;
	}

} 